/*++****************************************************************************
*
*	Name: max541.h
*   
*	Description:	This module provides defines and structures for the 
*					MAX541 single channel 0-5V 16-bit D/A chip from Maxim. 
*
*	Revision History:
*	Date	Who	Comments	
*	------	---	---------------------------------------------------------------
*	100927	RLP	Created
****************************************************************************--*/

#ifndef MAX541_H
#define MAX541_H


/******************************************************************************
								CONSTANTS AND MACROS
******************************************************************************/

#define MAX541_MAX_SPI_FREQ	10000000	// 10 mhz max speed

// MACROS

#define setCSLow(devInfo) 	PORTClearBits(devInfo->csPort, devInfo->csChan)
#define setCSHigh(devInfo)	PORTSetBits(devInfo->csPort, devInfo->csChan)

/******************************************************************************
								TYPEDEFS
******************************************************************************/

// structure to configure a MAX541 device. Can have multiple of these structures
// if more than one device is used.
typedef struct
{
	char		devName[7];		// device name
	SpiChannel 	spiChan;		// spi channel connected to max541
	UINT32		spiFreq;		// spi frequency in Hz
	IoPortId 	csPort;			// (out) chip select port; defined in "ports.h"; e.g. IOPORT_A, IOPORT_B, ... 
	UINT32		csChan;			// (out) chip select pin; defined in "ports.h"; e.g. BIT_0, BIT_1, ...
} MAX541DevInfo;


/******************************************************************************
								FUNCTION PROTOTYPES
******************************************************************************/

// Open device
extern INT16 MAX541Open(	SpiChannel	spiChan,	// SPI Device, eg SPI_CHANNEL1, SPI_CHANNEL1A, etc
							UINT32		spiFreq,	// spi frequency in Hz
							IoPortId 	csPort,		// (out) chip select port; defined in "ports.h"; e.g. IOPORT_A, IOPORT_B, ... 
							UINT32		csChan,		// (out) chip select pin; defined in "ports.h"; e.g. BIT_0, BIT_1, ...
							UINT32		pbClk );	// peripheral bus clock speed

extern INT16 MAX541Write(INT16 handle, UINT16 value);

extern INT16 MAX541Close( INT16 handle );

/******************************************************************************
								ERROR CODES
******************************************************************************/

#define MAX541_SUCCESS						0			// success
#define MAX541_BAD_HANDLE					1			// invalid handle

#endif
